package com.arvin.mapper;

import com.arvin.pojo.Exam;
import com.arvin.pojo.ExamInfo;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.time.LocalDate;
import java.util.List;

@Mapper
public interface ExamMapper {

    /**
     * 获取考试信息
     * @param studentId
     * @param stuName
     * @param className
     * @param examDate
     * @param examState
     * @param examScore
     * @return
     */
    List<ExamInfo> getExamInfo(String studentId, String stuName,String className,
                               LocalDate examDate, String examState,Integer examScore);

    /**
     * 添加考试信息
     * @param exam1
     */
    void insertExamInfo(Exam exam1);

    /**
     * 通过id获取考试信息
     * @param examId
     * @return
     */
    @Select("select * from t_exam where exam_id =#{examId}")
    Exam findByExamId(Integer examId);

    /**
     * 更新考试信息
     * @param exam
     */
    void updateExamInfo(Exam exam);

    /**
     * 删除考试信息
     * @param examId
     */
    @Delete("delete from t_exam where exam_id = #{examId} ")
    void deleteExam(Integer examId);

    /**
     * 学生批量通过获不通过考试
     * @param ids
     */
    void updateStateByExamIds(List<Integer> ids,String examState);

    /**
     * 通过考试id清除考试信息
     * @param examId
     */
    @Update("update t_exam set exam_date = null,exam_time = null,exam_state = ''," +
            "exam_score = null,update_time = now() " +
            "where exam_id = #{examId}")
    void clearByExamId(Integer examId);

    /**
     * 通过免试id清除免试信息
     * @param exemId
     */
    @Update("update t_exempt set exem_date = null,exem_time = null,exem_state = ''," +
            "exem_reason = '',exem_score = null")
    void clearByExemId(Integer exemId);
}
